package com.the4man.framework.util;

import org.apache.struts2.ServletActionContext;

/**
 * Created by lenovo on 2017/12/12.
 */
public class HtmlHelper {
    public HtmlHelper() {
    }

    public static String toIOSHtml(String title, String pic, String content, String datetime) {
        String html = "<!doctype html><html><head><meta charset=\"utf-8\"/>";
        String titletag = "<title>" + title + "</title>";
        html = html + titletag;
        String meta = "<meta name=\"viewport\" content=\"initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no\"><meta name=\"apple-mobile-web-app-capable\" content=\"yes\"><meta name='apple-touch-fullscreen' content='yes'><meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black\"><meta name=\"format-detection\" content=\"telephone=no\"><meta name=\"format-detection\" content=\"address=no\">";
        html = html + meta;
        String script = "<script type=\"text/javascript\">function a(){alert(document.getElementById('im_div').offsetTop);alert(document.getElementById('im_div').offsetLeft);};</script> ";
        html = html + script;
        String style = "<style>body{ margin:0; padding:0;}html,body{ margin-top:0; font-family:\"Microsoft YaHei\";}div,p,dl,dt,dd{ margin:0;padding:0}ul,li{ margin:0}img,a img{ border:0}html{height:100%; font-size:312.5%; width:100%;overflow-x:hidden;}.content p{ font-size:0.32rem;margin-bottom:16px; color:#8b8b8b;}.content{margin:22px 16px 11px 16px;}.content.im_div{ margin:16px 0 16px; position:relative; overflow:hidden;overflow:hidden;}.content img{max-width:100%;position:relative;width:100%; height:auto;border: none;}.content .im_div .reid{background: none repeat scroll 0 0 rgba(0, 0, 0, 0.5);bottom: 0.47rem;color: white;font-size: 0.24rem;height: 0.56rem;line-height: 0.56rem;position: absolute; text-align: center;idth: 80px;right:0.2rem;}.content .bott{padding-bottom:0.88rem;}.content .spe{margin-top:0.44rem;font-size:0.38rem;color:#000;}.content .spt{margin:4px 0 4px 0;font-size:0.30rem;font-weight:bold;color:#000;}.content .sp{margin:8px 0 8px 0;font-size:0.24rem;color:#7d7d7d;overflow-x:hidden;}.content .center{\tfont-size: 0.28%rem;}.content .center table{\twidth:100%;}.content .center table td{\twidth:none;\twidth:0;}</style>";
        html = html + style;
        html = html + "</head>";
        html = html + "<body><div class=\"content\">";
        html = html + "<div class=\"spe\"><a href=\"http://www.cnbdw.com/\"><img src=\"http://www.cnbdw.com/file/upload/201411/04/21-27-14-93-1.jpg\"></a></div>";
        html = html + "<div class=\"spt\">" + title + "</div>";
        html = html + "<div class=\"sp\">发布时间:<span class=\"date\"> " + datetime.substring(0, 10) + "</span></div>";
        html = html + "<div class=\"sp\">" + content + "</div>";
        html = html + "</div></body></html>";
        return html;
    }

    public static String toHtml(String title, String pic, String content, String datetime) {
        String useragent = ServletActionContext.getRequest().getHeader("User-Agent");
        return useragent != null && useragent.indexOf("android") != -1?toIOSHtml(title, pic, content, datetime):toIOSHtml(title, pic, content, datetime);
    }
}
